/*
	Copyright (C) 2009 Salil Bhagurkar
	
	This file is part of ViSE
	
	ViSE is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	ViSE is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with ViSE.  If not, see <http://www.gnu.org/licenses/>.
*/

/*SImple irq management code*/

#include <shared.h>

#define NR_IRQS 16

struct irq_handler {
	int (*irq_handler)();
}irq_handlers[NR_IRQS];


void main_irq(int irq_no)
{
	if(irq_handlers[irq_no].irq_handler)
		irq_handlers[irq_no].irq_handler();
	irq_ended(irq_no);
}

void arch_configure_interrupt_handler(int irq_no, int (*irq_handler)())
{
	irq_handlers[irq_no].irq_handler = irq_handler;
	enable_irq(irq_no);
}

void arch_remove_interrupt_handler(int irq_no)
{
	irq_handlers[irq_no].irq_handler = NULL;
	disable_irq(irq_no);
}

int init_irq()
{
	memset(irq_handlers, 0, sizeof(struct irq_handler) * NR_IRQS);
	arch_set_irq_call(main_irq);
	_set_all_irqs();
	init_pic();
	asm volatile ("sti");
	return 0;
}
